﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RelationExpertSystem.Relation
{
    public class Bastard : RelationBase
    {
        private static Bastard _singleton = new Bastard();
        public static Bastard Instance
        {
            get { return _singleton; }
        }

        private Bastard() { }

        public override bool IsRelated(Person a, Person b)
        {
            // b is a's Bastard IFF a is male AND b is a's son AND b's mother was never a's spouse
            return a.Sex == Sex.Male &&
                ((!Person.IsNull(a.Spouse) && !Person.IsNull(b.Mother) && a.Spouse != b.Mother) ||
                  a.KnownRelation(Ex_Spouse.Instance, b.Mother)) &&
                a.KnownRelation(Son.Instance, b);
        }

        public override IEnumerable<IRelation> GetDependencies()
        {
            return new HashSet<IRelation>(new IRelation[] {
                Spouse.Instance, Ex_Spouse.Instance, Son.Instance, Mother.Instance });
        }
    }
}
